<h2>Date Range Report</h2>
<?php
    $this->headTitle('Opportunity-Date Range Report');
    $this->dojo()->addLayer('/js/dojo/chart/layer.js');

    $acl = $this->acl;
    $user = $this->currentUser;
?>
<?php if ($acl->isAllowed($user,'access opportunity reports')): ?>
    <a href="/reports/index/index">Reports</a> | 
    <a href="/reports/opportunity">Opportunity reports</a> |
<?php endif; ?>

<?php if ($acl->isAllowed($user,'access opportunity reports')): ?>
    <a href="/reports/opportunity/daterange">Date range</a> |
<?php endif; ?>


<?php 
$opportunitySourceReportSummary = $this->opportunitySourceReportSummary; 
$opportunityStatusReportSummary = $this->opportunityStatusReportSummary;
?>

<?php if (!empty($opportunitySourceReportSummary)): ?>
    <?php if ($acl->isAllowed($user,'access opportunity reports')): ?>
    <a href="/reports/opportunity/csvexport/reportId/<?php echo $this->reportId; ?>">Export</a> |
    <a href="/reports/opportunity/browse/reportId/<?php echo $this->reportId; ?>">Browse </a>
    <?php endif; ?>
<?php endif; ?>
<br/><br/>
<?php echo $this->form; ?>

<div class="div_left">
<?php
    /*
     * Opportunity report summary by lead source
     */
    if (!empty($opportunitySourceReportSummary)): ?>
            <table class="data_table">
            <tr><th colspan="2">Opportunities by lead source</th></tr>
            <?php foreach ($opportunitySourceReportSummary as $key=>$value): ?>
            <?php    echo "<tr><td>" . $this->escape($key) . "</td><td>" . $this->escape($value) . "</td>"; ?>
            <?php endforeach; ?>
            </table>
</div>
<?php endif; ?>

<div class="div_left">
    <?php
    $toEncode = array();
    if (count($opportunitySourceReportSummary)):
        foreach ($opportunitySourceReportSummary as $key=>$value) {
            $toEncode[] = array(
                'y'=>$value,
                'text'=>$key,
                'stroke'=>'black',
                'tooltip'=>$key
            );
        }
    $json = json_encode($toEncode);
   ?>
      <div id="chartTwo" style="width: 300px; height: 400px;">
    </div>


    <script type="text/javascript">
        dojo.addOnLoad(function() {
            var dc = dojox.charting;
            var chartTwo = new dc.Chart2D("chartTwo");
            chartTwo.setTheme(dc.themes.MiamiNice).addPlot("default", {
                type: "Pie",
                font: "normal normal 9pt Tahoma",
                fontColor: "black",
                labelOffset: -30,
                radius: 120
            });
            chartTwo.addSeries("Series A", <?php echo $json; ?>);
            var anim_a = new dc.action2d.MoveSlice(chartTwo, "default");
            var anim_b = new dc.action2d.Highlight(chartTwo, "default");
            var anim_c = new dc.action2d.Tooltip(chartTwo, "default");
            chartTwo.render();
            
        });
    </script>

    <?php 
        endif;
    ?>
   
</div>
<div class="div_clear">
</div>

<div class="div_left">
    <?php
    /*
     * Opportunity report summary by status
     */
    if (!empty($opportunityStatusReportSummary)): ?>
            <table class="data_table">
            <tr><th colspan="2">Opportunities by sales stage</th></tr>
            <?php foreach ($opportunityStatusReportSummary as $key=>$value): ?>
            <?php    echo "<tr><td>". $this->escape($key) . "</td><td>" . $this->escape($value) . "</td>"; ?>
            <?php endforeach; ?>
            </table>
    <?php endif; ?>
</div>

<?php
    $toEncode = array();
    if (count($opportunityStatusReportSummary)):
        foreach ($opportunityStatusReportSummary as $key=>$value) {
            $toEncode[] = array(
                'y'=>$value,
                'text'=>$key,
                'stroke'=>'black',
                'tooltip'=>$key
            );
        }
    $json = json_encode($toEncode);
  ?>

  <div class="div_left">
        <div id="chartTwo3" style="width: 300px; height: 400px;">
        </div>

    <script type="text/javascript">
        dojo.addOnLoad(function() {
            var dc = dojox.charting;
            var chartTwo3 = new dc.Chart2D("chartTwo3");
            chartTwo3.setTheme(dc.themes.MiamiNice).addPlot("default", {
                type: "Pie",
                font: "normal normal 9pt Tahoma",
                fontColor: "black",
                labelOffset: -30,
                radius: 120
            }); 
            chartTwo3.addSeries("Series A", <?php echo $json; ?>);
            var anim_a = new dc.action2d.MoveSlice(chartTwo3, "default");
            var anim_b = new dc.action2d.Highlight(chartTwo3, "default");
            var anim_c = new dc.action2d.Tooltip(chartTwo3, "default");
            chartTwo3.render();
            
        });
    </script>

<?php 
    endif;
?>
</div>
<div class="div_clear">
</div>

